#!/usr/bin/python3
# -*- coding: utf-8 -*-

from collections import Iterable

from ._commons import db
from ..core.entities import PRJ_UNDEPLOYED


class JobRunnerPO(db.Model):
    """一次执行任务的记录。"""
    __tablename__ = 'JOB_RUNNER'

    id = db.Column('JR_ID', db.Integer, primary_key=True, nullable=False)
    project_name = db.Column('PRJ_NAME', db.ForeignKey('PROJECT.PRJ_NAME'), nullable=False)
    job_name = db.Column('JOB_NAME', db.String(100), nullable=False)
    job_type = db.Column('JOB_TYPE', db.String(100), nullable=False)
    submitted_time = db.Column('SUBMITTED_TIME', db.DateTime, nullable=False)
    started_time = db.Column('STARTED_TIME', db.DateTime, nullable=False)
    finished_time = db.Column('FINISHED_TIME', db.DateTime, nullable=False)
    status = db.Column('STATUS', db.Integer, nullable=False)


class JobLogPO(db.Model):
    """执行任务的日志。"""

    __tablename__ = 'JOB_RUNNER_LOG'

    job_runner_id = db.Column('JR_ID', db.ForeignKey('JOB_RUNNER.JR_ID'), nullable=False)
    seq_no = db.Column('SEQ_NO', db.Integer, primary_key=True, nullable=False)
    timestamp = db.Column('TIMESTAMP', db.DateTime, nullable=False)
    level = db.Column('LEVEL', db.Integer, nullable=False)
    msg = db.Column('MSG', db.String(1000), nullable=False)
